
# setup to allow the module to be imported from the same directory
#   the script is in
import sys
import os
filename = sys.argv[2]
filepath = os.path.dirname(filename)
sys.path.insert(0,filepath)
import OLib as MyLib
from math import *

import Blender
import Blender.Mathutils
from Blender.Mathutils import *
from Blender import *

image = MyLib.Image('MyScene')
#image.lookFrom(3.5,3,15)
image.lookFrom(-5+10*1.5,-1+5*1.5,15*1.5)
image.lookAt(0-5,-1,1)

pointList = [[0,0,0],[0,1,0],[1,1,0]]
obSkinShape = image.addCurveLine(pointList=pointList)

def curvePoints(t):
	z = t/36.0
	x = 5*sin(t*3.1415/180.0)
	y = 5*cos(t*3.1415/180.0)
	return [x,y,z]
tList = range(0,360,30)
pointList=[]
for t in tList:
	pointList.append(curvePoints(t))
obCurve = image.addCurveLine(pointList=pointList,closed=True)
    
image.addTube(tubePath=obCurve,tubeShape=obSkinShape,color=[1,0,0])
image.addCylinder(p1=[0,0,0],p2=[0,0,5])
image.addCylinder(p1=[0,0,0],p2=[0,0,-0.5],diameter=2.0,verts=24)
for t in range(0,360,45):
	p = curvePoints(t)
	p[2]*=2.0
	p[1]*=1.1
	p[0]*=1.1
	col = [t/360.0,1,1-t/360.0]
	image.addLighting(location=p,target=[0,0,0],type='Spot',energy=t/360.0,
	         color = col)
	image.addSphere(location=p,diameter=0.1)
	image.addCylinder(p1=p,p2=[0,0,0],diameter=0.1)

image.save(filepath+'\\images\\'+'test005_LightingTest.jpg')
